package com.pomelo.pm;

public abstract class Animal {

    String name;

    public Animal(String name) {
        this.name = name;
    }

    protected abstract void makeSound();
}

class Dog extends Animal {

    Dog(String name) {
        super(name);
    }

    @Override
    protected void makeSound() {
        System.out.println(super.name + "狗叫");
    }
}

class Cat extends Animal {
    public Cat(String name) {
        super(name);
    }

    @Override
    protected void makeSound() {
        System.out.println(super.name + "喵喵叫");
    }
}

class Cow extends Animal {

    public Cow(String name) {
        super(name);
    }

    @Override
    protected void makeSound() {
        System.out.println(super.name + "哞哞叫");
    }
}

class Zoo {
    private Animal[] animals;

    Zoo(Animal[] animals) {
        this.animals = animals;
    }

    public void makeSound() {
        for (int i = 0; i < animals.length; i++) {
            animals[i].makeSound();
        }
    }
}

class Test03 {

    public static void main(String[] args) {
        // Animal a1 = new Dog("汪汪特工队");
        // Animal[] animals = {a1, }
        Animal[] animals = {new Dog("汪汪特工队"), new Cat("黑猫警长"), new Cow("牛爷爷")};
        Zoo zoo = new Zoo(animals);
        zoo.makeSound();
    }
}
